package com.linh.trade;

import java.text.DecimalFormat;
import java.util.Date;

import com.linh.trade.data.Point;
import static com.linh.trade.Constants.DATE_TIME_FORMAT;
import static com.linh.trade.Constants.AMOUNT_FORMAT;
public class Trade {

	private static int counter = 0;

	private static final DecimalFormat ID_FORMAT = new DecimalFormat("0000");

	

	public enum State {
		OPEN, CLOSE
	};

	public enum Direction {
		LONG, SHORT
	}

	private double amount;

	private Point openingPoint;

	private Point closingPoint;

	private State state;

	private Direction direction;

	private Date timeStamp;

	private int id;

	public Trade() {
		counter++;
		id = counter;
		timeStamp = new Date();
	}

	public double getAmount() {
		return amount;
	}

	public void setAmount(double amount) {
		this.amount = amount;
	}

	public Point getOpeningPoint() {
		return openingPoint;
	}

	public void setOpeningPoint(Point openingPoint) {
		this.openingPoint = openingPoint;
	}

	public Point getClosingPoint() {
		return closingPoint;
	}

	public void setClosingPoint(Point closingPoint) {
		this.closingPoint = closingPoint;
	}

	public State getState() {
		return state;
	}

	public void setState(State state) {
		this.state = state;
	}

	public Direction getDirection() {
		return direction;
	}

	public void setDirection(Direction direction) {
		this.direction = direction;
	}

	public String getOpenLine() {

		StringBuilder builder = new StringBuilder();
		builder.append(DATE_TIME_FORMAT.format(timeStamp)).append(": ")
				.append("POS").append(ID_FORMAT.format(id)).append(" ")
				.append(direction).append(" ")
				.append(AMOUNT_FORMAT.format(amount)).append(" @ ")
				.append(openingPoint.getRate());

		return builder.toString();
	}

	public String getCloseLine() {

		StringBuilder builder = new StringBuilder();
		builder.append(DATE_TIME_FORMAT.format(timeStamp)).append(": ")
				.append("POS").append(ID_FORMAT.format(id)).append(" ")
				.append(state).append(" ").append(AMOUNT_FORMAT.format(amount))
				.append(" @ ").append(closingPoint.getRate());

		return builder.toString();
	}
}
